﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace BookStore.WebAnalyzer
{
    public static class XmlDocumentExtender
    {
        public static IList<XmlElement> GetNodesByTagAndAttributes(this XmlDocument doc, string tagName,string attriName, string attriValue)
        {
            IList<XmlElement> matches = new List<XmlElement>();
            IList<XmlElement> tagMatch = doc.GetElementsByTagName(tagName).Cast<XmlElement>().ToList();
            foreach (XmlElement tmp in tagMatch)
            {
                if (tmp.Attributes.Cast<XmlAttribute>().ToList().Where(x=>x.Name.Equals(attriName)).Count() > 0)
                {
                    if (tmp.Attributes[attriName].Value.ToLower().Equals(attriValue.ToLower()))
                        matches.Add(tmp);
                }
            }
            return matches;
        }
    }
}
